<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.springframework.org/schema/data/jaxb">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>LayuiCMSluyun</title>
    <link th:href="@{/managerstatic/plugins/layui/css/layui.css}" rel="stylesheet" media="all" />
</head>

<body>

<ul class="layui-timeline">
    <li class="layui-timeline-item">
        <i class="layui-icon layui-anim layui-anim-rotate layui-anim-loop layui-timeline-axis"></i>
        <div class="layui-timeline-content layui-text">
                <table id="demo"  lay-filter="test" class="layui-table" lay-data="{id: 'idTest'}"></table>
        </div>
    </li>
</ul>


<div id="add-main" style="display: none;">
    <form class="layui-form" action="" style="margin-top: 30px;margin-right: 40px">
        <input type="text" id="id" style="display:none" />
        <div class="layui-form-item">
            <label class="layui-form-label">姓名</label>
            <div class="layui-input-block">
                <input type="text" id="username" required  lay-verify="required" placeholder="请输入用户名称" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">vip等级</label>
            <div class="layui-input-block">
                <input type="text" id="vipId" required  lay-verify="required" placeholder="请输入vip等级" autocomplete="off" class="layui-input">
            </div>
        </div>
    </form>
</div>



<script th:src="@{/managerstatic/plugins/jquery.min.js}"></script>
<script th:src="@{/managerstatic/plugins/layui/layui.js}"></script>
<script th:inline="javascript">
    var url=[[@{/}]]
</script>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn" lay-event="insertForm1">所有用户</button>
        <button class="layui-btn" lay-event="insertForm">条件查询</button>
    </div>
</script>

<script th:inline="none">
    layui.use('table', function(){
        var table = layui.table;
    });


    //为了更新 js 缓存，可忽略
    layui.config({
        version: '1559794877398' //为了更新 js 缓存，可忽略
    });

    layui.use(['laydate', 'laypage', 'layer', 'table', 'carousel', 'upload', 'element', 'slider'], function(){
        var laydate = layui.laydate //日期
            ,laypage = layui.laypage //分页
            ,layer = layui.layer //弹层
            ,table = layui.table //表格
            ,carousel = layui.carousel //轮播
            ,upload = layui.upload //上传
            ,element = layui.element //元素操作
            ,slider = layui.slider //滑块


        //监听Tab切换
        element.on('tab(demo)', function(data){
            layer.tips('切换了 '+ data.index +'：'+ this.innerHTML, this, {
                tips: 1
            });
        });

        //执行一个 table 实例
        table.render({
            elem: '#demo'
            ,height: 420
            , id: 'tableOne'
            ,toolbar: '#toolbarDemo'
            ,url:url+'cinema/queryUserInfo1'//数据接口
            ,title: '用户表'
            ,page: true //开启分页
            ,toolbar: '#toolbarDemo' //开启工具栏，此处显示默认图标，可以自定义模板，详见文档
            ,totalRow: true //开启合计行
            ,cols: [[ //表头
                {type: 'checkbox', fixed: 'left'},
                {field:"id",title:'用户id',width:100,align:"center"},
                {field:"username",title:'用户名',width:100,align:"center"},
                {field:"telnumber",title:'电话',width:100,align:"center"},
                {field:"birthday",title:'生日',width:100,align:"center"},
                {field:"vipId",title:'用户级别',width:100,align:"center"},
                {field:"startDate",title:'开通vip时间',width:200,align:"center"},
                {field:"endDate",title:'vip到期时间',width:200,align:"center"},
                {field:"vname",title:'vip名称',width:100,align:"center"},
                {field:"vdiscount",title:'折扣',width:100,align:"center"},
                {field:"cinemaOderIds",title:'备注',width:100,align:"center"},
            ]]
        });
        //监听头工具栏事件
        table.on('toolbar(test)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            var data = checkStatus.data;
            switch(obj.event){
                case 'insertForm':
                    insertForm();
                    break;
                case 'insertForm1':
                    queryUser();
                    break;
            };
        });

        //监听行工具事件
        table.on('tool(test)', function(obj){ //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            var data = obj.data //获得当前行数据
                ,layEvent = obj.event; //获得 lay-event 对应的值
            if(layEvent === 'detail'){
                layer.msg('查看操作');
            } else if(layEvent === 'del'){
                layer.confirm('真的删除行么', function(index){
                    obj.del(); //删除对应行（tr）的DOM结构
                    layer.close(index);
                    //向服务端发送删除指令
                });
            } else if(layEvent === 'edit'){
                layer.msg('编辑操作');
            }
        });
        //分页
        laypage.render({
            elem: 'pageDemo' //分页容器的id
            ,count: 100 //总页数
            ,skin: '#1E9FFF' //自定义选中色值
            //,skip: true //开启跳页
            ,jump: function(obj, first){
                if(!first){
                    layer.msg('第'+ obj.curr +'页', {offset: 'b'});
                }
            }
        });
        slider.render({
            elem: '#sliderDemo'
            ,input: true //输入框
        });
    });

    function insertForm() {
        // emptyPlan();
        layer.open({
            // id:"addForm",
            type: 1,
            title:"信息查询",
            area: ['700px', '540px'],
            btn: ['确定', '取消'],
            content: $("#add-main"),
            yes:function(index){
                var table = layui.table;
                table.reload('tableOne', {
                    where: { //设定异步数据接口的额外参数，任意设
                        'username': $("#username").val(),
                        'vipId': $("#vipId").val(),
                    }
                    ,page: {
                        curr: 1 //重新从第 1 页开始
                    }
                }); //只重载数据
                $("#username").val("");
                $("#vipId").val("");
                layer.close(index)
            }
        });
    }

    //重载用户查询
    function  queryUser() {
        var table = layui.table;
        // 搜索条件
        var username= $("#username").val();
        var vipId = $("#vipId").val()
        table.reload('tableOne', {
            method: 'post',
            where: { //设定异步数据接口的额外参数，任意设
                'username': $("#username").val(),
                'vipId': $("#vipId").val(),
            }
            , page: {
                curr: 1
            },

        });
        // $('#motaikunag').modal('hide');
    }




</script>

</body>

</html>